package com.enjoy.tree;

public class BinarySearchTree {

    int data;

    BinarySearchTree left;

    BinarySearchTree right;

    public BinarySearchTree(int data) {
        this.data = data;
    }

    public void insert(BinarySearchTree root, int data) {
        if (root.data < data) {
            if (root.right == null) {
                root.right = new BinarySearchTree(data);
            } else {
                insert(root.right, data);
            }
        } else {
            if (root.left == null) {
                root.left = new BinarySearchTree(data);
            } else {
                insert(root.left, data);
            }
        }
    }

    public void find(BinarySearchTree root, int data) {
        if (root != null) {
            if (root.left.data > data) {
                find(root.left, data);
            } else if (root.right.data < data) {
                find(root.right, data);
            } else {
                System.out.println(root.data);
            }
        }
    }
}
